// Copyright (C) 2010 nodchip.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

#include "../JitRecompiler.h"
#include "JitRecompilerTest.h"

typedef u32 (*RecompiledFunction)(void*, void*, PowerPC::PowerPCState*);

void JitRecompilerTest::SetUp()
{
	memset(&ppcState, 0, sizeof(ppcState));
}

void JitRecompilerTest::TearDown()
{
	memset(&ppcState, 0, sizeof(ppcState));
}

void JitRecompilerTest::Execute(u32 instruction)
{
	Execute(UGeckoInstruction(instruction));
}

void JitRecompilerTest::Execute(UGeckoInstruction instruction)
{
	llvm::Module* module = new llvm::Module("Dolphin PowerPC Code", llvm::getGlobalContext());
	llvm::ExecutionEngine* engine = llvm::EngineBuilder(module).create();
	LLVMJit::JitRecompiler* recompiler = new LLVMJit::JitRecompiler(module, engine->getTargetData());

	llvm::Function* opcode = recompiler->GetFunction(instruction);

	RecompiledFunction func = (RecompiledFunction)engine->getPointerToFunction(opcode);
	func(NULL, NULL, &ppcState);

	delete recompiler;
	delete engine;
}
